home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 3 / CD ACTUAL 3.iso / linux / system / bsvc-1.000 / bsvc-1 / bsvc-1.0.4 / src / SimHector / cpu / Hector.cxx < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-26  |  5.8 KB  |  182 lines

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Hector.cxx - This is the Hector 1600 CPU class
  4. //
  5. // By: Bradford W. Mott
  6. // December 3,1993
  7. //
  8. ///////////////////////////////////////////////////////////////////////////////
  9.  
  10. #include "Tools.hxx"
  11. #include "RegInfo.hxx"
  12. #include "Hector.hxx"
  13.  
  14. ///////////////////////////////////////////////////////////////////////////////
  15. // Hector 1600 Class constructor
  16. ///////////////////////////////////////////////////////////////////////////////
  17. Hector::Hector(AddressSpace *addr)
  18.     : BasicCPU(
  19.         "Hector 1600",                          // Name of the CPU
  20.         2,                                      // Granularity in bytes
  21.         1,                                      // Number of address spaces
  22.         addr,                                   // Array of address spaces
  23.         "{InstructionAddress 4} {Mnemonic 35}", // Execution trace record
  24.         "InstructionAddress Mnemonic"           // Default trace entries
  25.       )
  26. {
  27.   // Allocate a data path
  28.   data_path = new DataPath(this);
  29.  
  30.   // Allocate a control unit
  31.   control_unit = new ControlUnit(*data_path);
  32.  
  33.   // Reset the system
  34.   Reset();
  35. }
  36.  
  37. ///////////////////////////////////////////////////////////////////////////////
  38. // The Hector 1600 Class destructor
  39. ///////////////////////////////////////////////////////////////////////////////
  40. Hector::~Hector()
  41. {
  42.   // Deallocate control unit
  43.   delete control_unit;
  44.  
  45.   // Deallocate data path
  46.   delete data_path;
  47. }
  48.  
  49. ///////////////////////////////////////////////////////////////////////////////
  50. // Perform a system reset
  51. ///////////////////////////////////////////////////////////////////////////////
  52. void Hector::Reset()
  53. {
  54.   // Reset all of the attached devices
  55.   address_space[0].Reset();
  56.  
  57.   // Init the Flags register with interrupts turned off
  58.   data_path->alu.SetFlags(I_FLAG);
  59.  
  60.   // Reset the data path's signals
  61.   data_path->ResetSignals();
  62.  
  63.   // Clear the data path's statistics
  64.   data_path->ClearStatistics();
  65. }
  66.  
  67. ///////////////////////////////////////////////////////////////////////////////
  68. // Return the value in the program counter
  69. ///////////////////////////////////////////////////////////////////////////////
  70. unsigned long Hector::ValueOfProgramCounter()
  71. {
  72.   return(data_path->register_set.GetRegister(PC));
  73. }
  74.  
  75. ///////////////////////////////////////////////////////////////////////////////
  76. // Return the name of the program counter
  77. ///////////////////////////////////////////////////////////////////////////////
  78. char* const Hector::NameOfProgramCounter()
  79. {
  80.   return(data_path->register_set.GetRegisterData(PC).name);
  81. }
  82.  
  83. ///////////////////////////////////////////////////////////////////////////////
  84. // Set the named register to the given value
  85. ///////////////////////////////////////////////////////////////////////////////
  86. void Hector::SetRegister(String name, String hex_value)
  87. {
  88.   unsigned int value;
  89.  
  90.   // Convert Hex String to an integer value
  91.   value=StringToInt(hex_value);
  92.  
  93.   // See if they are setting the ALU's flags
  94.   if(name=="FLAGS")
  95.   {
  96.     data_path->alu.SetFlags(value);
  97.     return;
  98.   }
  99.  
  100.   // See if they are setting any of the register file's registers
  101.   for(int t=0;t<data_path->register_set.NumberOfUserRegisters();++t) 
  102.   {
  103.     if(name==data_path->register_set.GetRegisterData(t).name)
  104.     {
  105.       data_path->register_set.SetRegister(t,value);
  106.       break;
  107.     }
  108.   }
  109. }
  110.  
  111. ///////////////////////////////////////////////////////////////////////////////
  112. // Clear the CPU's Statistics
  113. ///////////////////////////////////////////////////////////////////////////////
  114. void Hector::ClearStatistics()
  115. {
  116.   // Tell the data path object to clear the statistics
  117.   data_path->ClearStatistics();
  118. }
  119.  
  120. ///////////////////////////////////////////////////////////////////////////////
  121. // Build the statistics list for the StatisticalInformationList object
  122. ///////////////////////////////////////////////////////////////////////////////
  123. void Hector::BuildStatisticalInformationList(StatisticalInformationList* list)
  124. {
  125.   String entry;;
  126.  
  127.   // Add the number of reads 
  128.   entry = "# Reads:  ";
  129.   entry += IntToDecimal(data_path->NumberOfReads(),8);
  130.   list->Append(entry);
  131.  
  132.   // Add the number of writes 
  133.   entry = "# Writes: ";
  134.   entry += IntToDecimal(data_path->NumberOfWrites(),8);
  135.   list->Append(entry);
  136.  
  137.   // Add the number of cycles 
  138.   entry = "# Cycles: ";
  139.   entry += IntToDecimal(data_path->NumberOfCycles(),8);
  140.   list->Append(entry);
  141. }
  142.  
  143. ///////////////////////////////////////////////////////////////////////////////
  144. // Build the register list for the RegisterInformationList object
  145. ///////////////////////////////////////////////////////////////////////////////
  146. void Hector::BuildRegisterInformationList(RegisterInformationList *list)
  147. {
  148.   int t;
  149.   String value;
  150.  
  151.   // Add all of the register's in the register file to the list
  152.   for(t=0;t<data_path->register_set.NumberOfUserRegisters();++t)
  153.   {
  154.     value=IntToString(data_path->register_set.GetRegister(t),4);
  155.     list->Append(data_path->register_set.GetRegisterData(t).name,
  156.                 value, data_path->register_set.GetRegisterData(t).description);
  157.   }
  158.  
  159.   // Add the FLAGS register in the ALU to the list
  160.   value=IntToString(data_path->alu.GetFlags(),4);
  161.   list->Append("FLAGS",value,"FLAGS:  CVNZI-----------");
  162. }
  163.  
  164. ///////////////////////////////////////////////////////////////////////////////
  165. // Execute the next instruction
  166. ///////////////////////////////////////////////////////////////////////////////
  167. const char* Hector::ExecuteInstruction(String& trace_record, int trace_flag)
  168. {
  169.   const char* error_message;
  170.  
  171.   error_message=control_unit->ExecuteInstruction(trace_record, trace_flag);
  172.   return(error_message);
  173. }
  174.  
  175. ///////////////////////////////////////////////////////////////////////////////
  176. // Handle an interrupt request from a device
  177. ///////////////////////////////////////////////////////////////////////////////
  178. void Hector::InterruptRequest(BasicDevice* device, int level)
  179. {
  180. }
  181.  
  182.